const { list } = require("./mock");
const bodyParser = require('body-parser')
module.exports = (app) => {
  app.use(bodyParser.json())
  app.post("/api/more/list", (req, res) => {
    const { value, filterValue: { area, type, desc } } = req.body

    const newList = [...list].filter(v => {
      const flag1 = v.title.includes(value);
      let flag2 = true, flag3 = true;

      if(area && area !== '全部区域') {
        flag2 = v.area === area
      }

      if(type && type !== '全部类型') {
        flag3 = v.type === type
      }
      console.log(flag1, flag2, flag3)
      return flag1 && flag2 && flag3
    }).sort((p, n) => {
      switch(desc) {
        case 'a':
          return 0
        case 'b':
          return n.sell - p.sell
        case 'c':
          return n.house - p.house
        case 'd':
          return n.look - p.look
      }
    })

    res.send({
      code: 200,
      data: newList,
    });
  });
};
